package com.lich.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import com.lich.dao.AccessManagerMapper;
import com.lich.entity.AccessManager;
import com.lich.entity.vo.Page;

@Service
public class AccessManagerService {
	
	@Resource
	private AccessManagerMapper accessManagerMapper;

	public Integer selectByUrl(String url){
		if (StringUtils.isBlank(url))
			return 0;
		Map<String , Object> params = new HashMap<>();
		params.put("url", url);
		return accessManagerMapper.selectByUrl(params);
	}
	
	public Page<AccessManager> list(Page<AccessManager> page){
		int count = accessManagerMapper.count();
		if(count<=0){
			page.setCount(0);
			return page;
		}
		List< AccessManager> list = accessManagerMapper.list(page);
		page.setCount(count);
		page.setList(list);
		return page;
	}
	
	
	public int delete(AccessManager accessManager){
		return accessManagerMapper.deleteByPrimaryKey(accessManager.getId());
	}
	
	
	
	public int updata(AccessManager accessManager){
		return accessManagerMapper.updateByPrimaryKey(accessManager);
	}
	
	public int insert(AccessManager accessManager){
		return accessManagerMapper.insert(accessManager);
	}
	
}
